package com.chenken;

import java.io.UnsupportedEncodingException;
import java.util.Comparator;

public class Test {

	public static void main(String[] args) throws UnsupportedEncodingException {
		test1();
		test2();
	}

	private static void test1() {
		System.out.println("年龄较大的优先");
		PriorityQueue<Person> queue = new PriorityQueue<Person>(new Comparator<Person>() {
			/**
			 * 年龄较大的优先
			 */
			@Override
			public int compare(Person o1, Person o2) {
				return o1.getAge() - o2.getAge();
			}
		});
		
		queue.enQueue(new Person("a", 20));
		queue.enQueue(new Person("b", 10));
		queue.enQueue(new Person("c", 60));
		queue.enQueue(new Person("d", 50));
		queue.enQueue(new Person("e", 2));
		queue.enQueue(new Person("f", 30));
		
		while(!queue.isEmpty()) {
			System.out.println(queue.deQueue());
		}
	}
	
	private static void test2() {
		System.out.println("年龄较小的优先");
		PriorityQueue<Person> queue = new PriorityQueue<Person>(new Comparator<Person>() {
			/**
			 * 年龄较小的优先
			 */
			@Override
			public int compare(Person o1, Person o2) {
				return o2.getAge() - o1.getAge();
			}
		});
		
		queue.enQueue(new Person("a", 20));
		queue.enQueue(new Person("b", 10));
		queue.enQueue(new Person("c", 60));
		queue.enQueue(new Person("d", 50));
		queue.enQueue(new Person("e", 2));
		queue.enQueue(new Person("f", 30));
		
		while(!queue.isEmpty()) {
			System.out.println(queue.deQueue());
		}
	}
	
}
